package main

import (
	"fmt"
	"os"
	"x1aCron/internal/cli"
	"x1aCron/internal/daemon"
	"x1aCron/internal/global"
	"x1aCron/internal/utils"
)

func main() {
	if os.Getenv("DAEMON") == "1" {
		daemon.DaemonToDo()
	} else {
		isExists := utils.ProcessExistsFromFile(global.PID)
		cli.ParseArgs()

		if !isExists {
			if cli.GetStart() {
				// 启动守护进程
				go utils.SpinnerWaiting()
				daemon.CreateDaemon()
			} else {
				fmt.Println("x1aCron is not running. Please start it with -start option.")
			}
		} else {
			utils.SendDataAndGetResponses(cli.GenerateTasks())
		}
	}
}
